package xyz.yuzegod.megawalls.classes.mythic.mole;

import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;
import xyz.yuzegod.megawalls.MegaWalls;
import xyz.yuzegod.megawalls.classes.Classes;
import xyz.yuzegod.megawalls.classes.Skill;
import xyz.yuzegod.megawalls.game.GamePlayer;
import xyz.yuzegod.megawalls.stats.KitStatsContainer;
import xyz.yuzegod.megawalls.util.ItemBuilder;
import xyz.yuzegod.megawalls.util.StringUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class ThirdSkill extends Skill
{
    public ThirdSkill(final Classes classes) {
        super("垃圾食品", classes);
    }
    
    @Override
    public int maxedLevel() {
        return 3;
    }
    
    @Override
    public double getAttribute(final int level) {
        switch (level) {
            case 1: {
                return 0.07;
            }
            case 2: {
                return 0.14;
            }
            case 3: {
                return 0.21;
            }
            default: {
                return 0.07;
            }
        }
    }
    
    @Override
    public List<String> getInfo(final int level) {
        final List<String> lore = new ArrayList<String>();
        if (level == 1) {
            lore.add(" §8▪ §7用锹挖掘时,有§a" + StringUtils.percent(this.getAttribute(level)) + "§7几率掉落");
            lore.add("   §7垃圾食品。你有20%几率回");
            lore.add("   §7收吃掉的金苹果。");
            return lore;
        }
        lore.add(" §8▪ §7用锹挖掘时,有§8" + StringUtils.percent(this.getAttribute(level - 1)) + " ➜ §a" + StringUtils.percent(this.getAttribute(level)) + "§7几率掉落");
        lore.add("   §7垃圾食品。你有20%几率回");
        lore.add("   §7收吃掉的金苹果。");
        return lore;
    }
    
    @Override
    public void upgrade(final GamePlayer gamePlayer) {
        final KitStatsContainer kitStats = gamePlayer.getPlayerStats().getKitStats(this.getClasses());
        kitStats.addSkill3Level();
    }
    
    @Override
    public int getPlayerLevel(final GamePlayer gamePlayer) {
        return gamePlayer.getPlayerStats().getKitStats(this.getClasses()).getSkill3Level();
    }
    
    @Override
    public boolean use(final GamePlayer gamePlayer, final KitStatsContainer kitStats) {
        final Player player = gamePlayer.getPlayer();
        if (MegaWalls.getRandom().nextInt(600) <= 20) {
            player.getInventory().addItem(new ItemStack[] { new ItemBuilder(Material.GOLDEN_APPLE).setDisplayName("§e吃掉的金苹果").build() });
        }
        if (MegaWalls.getRandom().nextInt(600) <= this.getAttribute(kitStats.getSkill3Level()) * 100.0) {
            if (new Random().nextInt(1) == 1) {
                player.getInventory().addItem(new ItemStack[] { new ItemBuilder(Material.PUMPKIN_PIE).setDisplayName("§e垃圾派").build() });
            }
            else {
                player.getInventory().addItem(new ItemStack[] { new ItemBuilder(Material.COOKIE).setDisplayName("§e垃圾曲奇").build() });
            }
        }
        return true;
    }
}
